﻿using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;
using System.Linq;
using System;
using System.Web.Mvc;

namespace CharacterCreation.Business.ViewModels
{
    [Description("Character")]
    public class VMCharacter : ViewModelBase
    {

        [Required(ErrorMessage = "The name of the character is required")]
        [StringLength(50, MinimumLength = 3)]
        [Display(Name = "Charact name")]
        public string Name { get; set; }

        [Display(Name = "Description")]
        [DataType(DataType.MultilineText)]
        public string Description { get; set; }

        public string Race { get; set; }

        public VMCharacterStatistic Strength { get { return this.Statistics.First(c => c.Name == "Strength"); } }
        public VMCharacterStatistic Dexterity { get { return this.Statistics.First(c => c.Name == "Dexterity"); } }
        public VMCharacterStatistic Fighting { get { return this.Statistics.First(c => c.Name == "Fighting"); } }
        public VMCharacterStatistic Constitution { get { return this.Statistics.First(c => c.Name == "Constitution"); } }
        public VMCharacterStatistic Perception { get { return this.Statistics.First(c => c.Name == "Perception"); } }
        public VMCharacterStatistic Intelligence { get { return this.Statistics.First(c => c.Name == "Intelligence"); } }
        public VMCharacterStatistic WillPower { get { return this.Statistics.First(c => c.Name == "Will power"); } }
        public VMCharacterStatistic Charisma { get { return this.Statistics.First(c => c.Name == "Charisma"); } }
        public VMCharacterStatistic HitPoints { get { return this.Statistics.First(c => c.Name == "Hit points"); } }
        public VMCharacterStatistic Essence { get { return this.Statistics.First(c => c.Name == "Essence"); } }


        public List<VMCharacterStatistic> Statistics { get; set; }
        public List<VMCharacterSkill> Skills { get; set; }


        public static VMCharacter Create()
        {
            VMCharacter character = new VMCharacter() { Id = Guid.NewGuid() };
            List<VMCharacterStatistic> stats = new List<VMCharacterStatistic>();

            stats.Add(new VMCharacterStatistic() { OrderIndex = 0, CharacterId = character.Id, Name = "Strength" });
            stats.Add(new VMCharacterStatistic() { OrderIndex = 1, CharacterId = character.Id, Name = "Dexterity" });
            stats.Add(new VMCharacterStatistic() { OrderIndex = 2, CharacterId = character.Id, Name = "Fighting" });
            stats.Add(new VMCharacterStatistic() { OrderIndex = 3, CharacterId = character.Id, Name = "Constitution" });
            stats.Add(new VMCharacterStatistic() { OrderIndex = 4, CharacterId = character.Id, Name = "Perception" });
            stats.Add(new VMCharacterStatistic() { OrderIndex = 5, CharacterId = character.Id, Name = "Intelligence" });
            stats.Add(new VMCharacterStatistic() { OrderIndex = 6, CharacterId = character.Id, Name = "Will power" });
            stats.Add(new VMCharacterStatistic() { OrderIndex = 7, CharacterId = character.Id, Name = "Charisma" });
            stats.Add(new VMCharacterStatistic() { OrderIndex = 8, CharacterId = character.Id, Name = "Hit points" });
            stats.Add(new VMCharacterStatistic() { OrderIndex = 9, CharacterId = character.Id, Name = "Essence" });
            character.Statistics = stats;

            return character;
        }
    }
}
